package com.foreveredu.propms.persist.hibernate;

import java.util.List;

import com.foreveredu.propms.domain.User;
import com.foreveredu.propms.persist.IUserDao;

public class HibernateUserDao extends HibernateAbstractDao<User, Integer> implements IUserDao {

	private static final long serialVersionUID = 1L;
	
	public HibernateUserDao() {
		super(User.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public User findUserByUserName(String username) {
		List<User> userList = this.getHibernateTemplate().find("from User user where user.username = ?", username);
		User user = null;
		if (userList != null && userList.size() > 0) {
			user = userList.get(0);
		}
		return user;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public User findUserById(int id) {
		
		List<User> userList = this.getHibernateTemplate().find("from User user where user.id = ?", id);
		User user = null;
		if (userList != null && userList.size() > 0) {
			user = userList.get(0);
		}
		return user;
	}
	
	
}
